﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using ProjectBase.Core;
using ProjectBase.Core.Web;
using ProjectBase.Mvc;

using Survey.Common;
using Survey.Entity;
using Survey.Common.Models;

namespace Survey.Web.Controls
{
    public class AnswerRow : ContentControl<IQuestionModel, AnswerRow>, ITableRow
    {
        protected override void BuildControls()
        {
            if (Item.IsNull())
            {
                return;
            }

            var index = Index.IsEmpty()
               ? Item.Position.ToString(CultureInfo.InvariantCulture)
               : Index;

            var prefix = Prefix.Extend(index);

            Controls.Add(new TableRow(GetAttribute(Attr.Class))
            {
                new TableCell("w40")
                {
                    new TextOrInput().SetSourceProperty(() => index)
                        .SetCssClassName("w40")
                        .SetInputName("Position")
                        .SetPrefix(prefix),
                },
                new TableCell
                {
                    new TextOrInput().SetSourceProperty(() => Item.Title)
                        .SetPrefix(prefix)
                },
                new TableCell
                {
                    new TextOrInput().SetSourceProperty(() => Item.Description)
                        .SetPrefix(prefix)
                },
                Model.IsActionDetail() ? null :
                new TableCell("Remove")
                {
                    Model.IsActionDetail()
                    ? null
                    : new Anchor("center doRemoveItem"){ new Literal("X") },

                    new Input(InputType.Hidden)
                        .SetCssClassName("CollectionItem")
                        .SetName(Prefix.Extend("ExistingIDs"))
                        .SetValue(index),
                },
            }.SetId(GetAttribute(Attr.ID))
            );
        }

        public virtual Answer Item { get; set; }
        public virtual string Index { get; set; }
        public virtual string Prefix { get; set; }
    }
}